from flask import Flask,request,jsonify,Blueprint
from views.add_cates import  bp_cates
# 导入jwt 进行token解密
from utils.jwt_c import jwte

app = Flask(__name__)
# 导入配置文件
from config import Config
# 加载配置文件
app.config.from_object(Config)
#解决跨域
from flask_cors import CORS
CORS(app)
# 导入数据库
from db import db1
# 导入蓝图
from workss import  bp_work
# 导入用户蓝图
from views.adminuser import  adminusers
# 导入登录蓝图
from views.login_adminuser import bp_auser
app.register_blueprint(adminusers,url_prefix="/admin/")
app.register_blueprint(bp_work,url_prefix="/work/")
app.register_blueprint(bp_cates,url_prefix='/cates/')
# 注册管理员
app.register_blueprint(bp_auser,url_prefix='/auser/')




# 测试添加展示 
# @app.route('/test')
def test():
    # sql1 = "insert into test values(0,'焦长豪')"
    # db1.update(sql1)
    # sql = "select * from test"
    # res = db1.find_all(sql)
    # return jsonify({"list":res})
    # # return res
    return 'ok'

# 拦截器
# 每次请求判断token是否存在 是否过期
@app.before_request
def before_request():
    # 查看路径 request.path
    # print(request.path)
    # # 查看是否携带token
    # print(request.headers['Token'])
    white = ['/sendmsm','/mobile_login']
    if request.path not in white:
        # 获取token
        token = request.headers['TOken']
        payload = jwte.j_d(token)
        print(payload)

    return 'ok'



# 跨域
if __name__ == "__main__":
    app.run(debug=True)